package com.ql.mangersystem.controller;

import com.ql.mangersystem.common.Page;
import com.ql.mangersystem.common.Result;
import com.ql.mangersystem.entity.dto.LogsPageDTO;
import com.ql.mangersystem.entity.po.Logs;
import com.ql.mangersystem.service.LogsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/logs")
@RestController
@Slf4j
@Api("日志接口")
@CrossOrigin(value = "http://localhost:5173/")
public class LogsController {
    @Resource
    private LogsService logsService;

    /**
     * 删除信息
     */
    @ApiOperation("删除信息")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        int result =logsService.delete(id);
        if (result <=0) {
            return Result.error("删除失败");
        }
        return Result.success("删除成功");
    }
    /**
     * 批量删除信息
     */
    @ApiOperation("批量删除信息")
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestParam List<Integer> ids) {
        int result = logsService.deleteBatch(ids);
        if (result <=0) {
            return Result.error("删除失败");
        }
        return Result.success("删除成功");
    }
    /**
     * 分页模糊查询
     */
    @ApiOperation("分页模糊查询")
    @PostMapping("/page")
    public Result page(@RequestBody LogsPageDTO logsPageDTO) {
//        System.out.println(logsPageDTO);
        Page<Logs> logs =logsService.page(logsPageDTO);
        if (logs==null) {
            return Result.error("查询失败");
        }
        return Result.success(logs);
    }
}
